from get_data import get_price
from datetime import datetime, timedelta
import pandas as pd

print("=== 调试数据获取问题 ===")

# 测试不同的参数组合
symbol = '159915.XSHE'
end_date = datetime(2025, 9, 23)
count = 25

print(f"测试股票: {symbol}")
print(f"结束日期: {end_date}")
print(f"需要天数: {count}")

# 1. 只用count参数
print("\n1. 只使用count参数:")
data1 = get_price(symbol, count=count)
if data1 is not None:
    print(f"获取到 {len(data1)} 条数据")
    print("日期范围:", data1.index.min(), "到", data1.index.max())
    print("最近5天:")
    print(data1.tail())
else:
    print("未获取到数据")

# 2. 使用end_date + count
print(f"\n2. 使用end_date + count:")
data2 = get_price(symbol, end_date=end_date, count=count)
if data2 is not None:
    print(f"获取到 {len(data2)} 条数据")
    print("日期范围:", data2.index.min(), "到", data2.index.max())
    print("最近5天:")
    print(data2.tail())
else:
    print("未获取到数据")

# 3. 获取更多数据看看实际情况
print(f"\n3. 获取更多数据 (count=50):")
data3 = get_price(symbol, count=50)
if data3 is not None:
    print(f"获取到 {len(data3)} 条数据")
    print("日期范围:", data3.index.min(), "到", data3.index.max())
    
    # 检查是否包含目标日期
    target_date = pd.to_datetime(end_date)
    if target_date in data3.index:
        print(f"✅ 包含目标日期 {target_date.date()}")
    else:
        print(f"❌ 不包含目标日期 {target_date.date()}")
        print("最接近的日期:", data3.index[data3.index <= target_date].max() if len(data3.index[data3.index <= target_date]) > 0 else "无")
    
    # 计算到目标日期的实际天数
    filtered_data = data3[data3.index <= target_date]
    print(f"到目标日期的实际数据天数: {len(filtered_data)}")
    
else:
    print("未获取到数据")

print("\n=== 调试完成 ===")